package com.advaita.license;

import java.util.Calendar;
import java.util.Date;

class TestLicense implements PathwayOptions {

	// Test Case - some random Client Selections...
	static String[] passedClientSelections = { "Homo sapien",
			"Drosophilla melanogaster (Fruit Fly)", "Gallus gallus (chicken)",
			"HitachiSoft", "Operon", "Applied Biosystems", "GeneBank Gis",
			"Gene Symbol", "KEGG", "All Genes with GSA & PADOG",
			"All Genese Impact Analysis" };

	static String macAddress = "0010B5C4666A";

	Date expirationDate = new Date();

	// ------------------------------------------------------------------------------------------------------------------
	// ------------------------------------------------------------------------------------------------------------------

	protected static void populateATestCustomer(Customer testCustomer) {
		Customer.populateBlankCustomer(testCustomer);

		// Change the isEnabled value to True for only the options selected in
		// the String array: passedClientSelections

		for (String passedClientSelectionsIterator : passedClientSelections) {
			for (Selection organismIterator : testCustomer.licenseInfo
					.getOrganisms()) {
				if (organismIterator.getSelection().contains(
						passedClientSelectionsIterator)) {
					organismIterator.setIsEnabled(true);
					// System.out.println("just set " +
					// organismIterator.getSelection() + " to " +
					// organismIterator.getIsEnabled() );
				}
				;
			}
			;

			for (Selection microArrayIterator : testCustomer.licenseInfo
					.getMicroArray()) {
				if (microArrayIterator.getSelection().contains(
						passedClientSelectionsIterator)) {
					microArrayIterator.setIsEnabled(true);
					// System.out.println("just set " +
					// microArrayIterator.getSelection() + " to " +
					// microArrayIterator.getIsEnabled() );
				}
				;
			}
			;

			for (Selection geneIDIterator : testCustomer.licenseInfo
					.getGeneID()) {
				if (geneIDIterator.getSelection().contains(
						passedClientSelectionsIterator)) {
					geneIDIterator.setIsEnabled(true);
					// System.out.println("just set " +
					// geneIDIterator.getSelection() + " to " +
					// geneIDIterator.getIsEnabled() );
				}
				;
			}
			;

			for (Selection pathwayDBIterator : testCustomer.licenseInfo
					.getDatabase()) {
				if (pathwayDBIterator.getSelection().contains(
						passedClientSelectionsIterator)) {
					pathwayDBIterator.setIsEnabled(true);
					// System.out.println("just set " +
					// pathwayDBIterator.getSelection() + " to " +
					// pathwayDBIterator.getIsEnabled() );
				}
				;
			}
			;

			for (Selection analysisIterator : testCustomer.licenseInfo
					.getAnalysis()) {
				if (analysisIterator.getSelection().contains(
						passedClientSelectionsIterator)) {
					analysisIterator.setIsEnabled(true);
					// System.out.println("just set " +
					// analysisIterator.getSelection() + " to " +
					// analysisIterator.getIsEnabled() );
				}
				;
			}
			;

		}

		// Add MAC Address
		macAddress = "0010B5C4666A";
		testCustomer.licenseInfo.setMacAddress(macAddress);

		// Add Expiration Date
		Date expirationDate = new Date();
		Date oldDate = new Date();
		System.out.println ("here1 " + expirationDate);
		Calendar Cal = Calendar.getInstance();
		Cal.setTime(expirationDate);
		Cal.add(Calendar.YEAR, 1);
		Cal.add(Calendar.MONTH, 6);
		expirationDate = Cal.getTime();
		if(oldDate.compareTo(expirationDate)>0){
    		System.out.println("Error License is espired");
		}
		else
			System.out.println("Good date");
		System.out.println ("here2 " + expirationDate);
		testCustomer.licenseInfo.setExpDate(expirationDate);


		// 53217115116157196102106052315
		//MAC Address : 0010B5C4666A
		//Expiration Date : 05/23/15
	}

	// ------------------------------------------------------------------------------------------------------------------
	// ------------------------------------------------------------------------------------------------------------------

	public static void main(String[] args) {

		String testKey;

		// Create Test Customer:
		Customer testCustomer = new Customer();
		populateATestCustomer(testCustomer);
		License.generateSuperSecretcode(testCustomer);
		Customer.showSelections(testCustomer);

		// Populate Customer Details based on a key:
		testKey = testCustomer.getLicenseInfo().getKey(); // Can fill in any
															// valid 29 digit
															// Key in String
															// format.
		Customer returnedPopulatedCustomer = new Customer();
		returnedPopulatedCustomer = License.decodeSuperSecretCode(testKey);
		Customer.showSelections(returnedPopulatedCustomer);

	}

}
